/*
    constants.h

    This is part of OsEID (Open source Electronic ID)

    Copyright (C) 2015-2021 Peter Popovec, popovec.peter@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    definition of constant values for eliptic curves, oids etc

*/

#ifndef CONSTANTS_H
#define CONSTANTS_H
// N_ identificator
// S_ size
// C_ byte string

/* *INDENT-OFF* */
// MyEID applet information
#define N_CARD_ID	1
#define S_CARD_ID	20
#if 1
#define C_CARD_ID	  'O','s','E','I','D',4,5,2,\
                          0,0,0,0,0,0,0,0,0,1,0,0
#else
#define C_CARD_ID	  'O','s','E','I','D',4,2,16,\
                          0,0,0,0,0,0,0,0,0,1,0,0
#endif
// MyEID card  capabilities
#define N_CARD_CAP_ID	2
#define S_CARD_CAP_ID	11
#define L_RSA		2048
#if MP_BYTES >= 66
#define L_ECC		521
#else
#define L_ECC		384
#endif
#define L_DES		192
#define L_AES		256

#define CAP_RSA		0x01
#define CAP_DES		0x02
#define CAP_AES		0x04
#define CAP_ECDSA	0x08
// bit 4 = Grid Pin
// bit 5 = PIV emulation
// 6..15 RFU

#define C_CARD_CAP_ID	1, 0,(CAP_RSA|CAP_DES|CAP_AES|CAP_ECDSA), (L_RSA/256),(L_RSA&255), (L_DES/256),(L_DES&255), (L_AES/256),(L_AES&255), (L_ECC/256),(L_ECC&255)

// product of first 43 or 130 primes (used in primality tests)
#if 0
#define N_GCD_PRIMES   3
#define S_GCD_PRIMES   32
#define C_GCD_PRIMES    0x77, 0x86, 0xe9, 0x2b, 0x35, 0x93, 0x5b, 0xc0,\
                        0x2a, 0xed, 0x9a, 0x81, 0x87, 0x58, 0x15, 0x9f,\
                        0x88, 0x86, 0x95, 0x43, 0x51, 0x35, 0x24, 0xf5,\
                        0xc0, 0xb3, 0x54, 0x56, 0x6f, 0x5b, 0xf0, 0xdb
#else
#define N_GCD_PRIMES    3
#define S_GCD_PRIMES   128
#define C_GCD_PRIMES    0x79,0x01,0xF3,0x11,0x60,0xA3,0x1A,0x06,0x8F,0x36,0x36,0xDF,0x11,0xD4,0x86,0x51,\
                        0x0E,0xC7,0x4F,0xEC,0x7D,0xCE,0xC0,0xD1,0x3D,0x78,0xE2,0xDA,0xE5,0xB6,0xBB,0x35,\
                        0xCB,0x74,0x5C,0xAC,0x8B,0xF1,0x8E,0x63,0x56,0x8E,0xE5,0x18,0x55,0x05,0xEE,0x86,\
                        0xAD,0x33,0xB2,0x98,0x4D,0xB2,0xC9,0x1A,0x07,0x1B,0xE9,0x15,0xAD,0xE0,0xF6,0xAE,\
                        0x91,0x6E,0x99,0x70,0xFD,0x6A,0xB1,0x94,0x77,0x6B,0x65,0x50,0x57,0x0F,0xB1,0xF9,\
                        0x82,0xFC,0xEF,0x76,0xF5,0x0E,0x08,0xA7,0x8F,0xFE,0x06,0xA2,0x3C,0x7C,0x10,0x1C,\
                        0x02,0x4C,0xFA,0x69,0x7D,0x6B,0xB5,0x7D,0xD8,0x06,0x12,0x12,0xDF,0xEF,0x37,0xB8,\
                        0x72,0xBD,0x20,0x6C,0xBA,0xB1,0x62,0x0F,0xE8,0x4B,0xF2,0x70,0xF8,0x5F,0xC8,0x02
#endif

// Digest info prefixes,  do not change numbering, this corresponds to TAG 0x80 Algorithm reference upper nible
// 0Xh ho hash algo, 1Xh SHA1 ... 6Xh SHA512
#define N_PSHA1_prefix	0x71
#define S_PSHA1_prefix	15
#define C_PSHA1_prefix 	  0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14

#define N_PRIPEMD160_prefix	N_PSHA1_prefix+1
#define S_PRIPEMD160_prefix	15
#define C_PRIPEMD160_prefix	0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14

#define N_PSHA224_prefix	N_PSHA1_prefix+2
#define S_PSHA224_prefix	19
#define C_PSHA224_prefix	0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c

#define N_PSHA256_prefix	N_PSHA1_prefix+3
#define S_PSHA256_prefix	19
#define C_PSHA256_prefix	0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20

#define N_PSHA384_prefix 	N_PSHA1_prefix+4
#define S_PSHA384_prefix 	19
#define C_PSHA384_prefix	0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30

#define N_PSHA512_prefix 	N_PSHA1_prefix+5
#define S_PSHA512_prefix 	19
#define C_PSHA512_prefix	0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40

#define N_PMD5_prefix		N_PSHA1_prefix+6
#define S_PMD5_prefix		18
#define C_PMD5_prefix		0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10

#define N_FS_INIT_DATA	0x0f
#define	S_FS_INIT_DATA	42
#define	C_FS_INIT_DATA	0x00,0x3f,0xff,0x7f,0x00,0x00,0x00,0x00,0x38,0x11,0x3f,0xff,0x02,0x00,0xe0,\
			0x15,0x50,0xff,0x7f,0x01,0x00,0x00,0x00,0x38,0x11,0x1f,0xff,0x02,0x00,0xec,\
                        0xa0,0x00,0x00,0x00,0x63,0x50,0x4b,0x43,0x53,0x2d,0x31,0x35

/////////////////////////////////////////////////////////////////////////////////////////////
// ECC parameters: - use N_ below 0x3f, check ec.h / ec.c form MASK bits 6,7 are used to
// signalize special values of A (A=0 A=-3) to speed up ec_double and checking if point is on curve
// N_ identificator
// S_ size
// C_ byte string
/////////////////////////////////////////////////////////////////////////////////////////////
// curve ID (needed in ec.h/ec.c to determine fast reduction algo,
// then curve parameters incremented by 1... (prime,order,a,b,Gx,Gy)
#define C_P192V1	0x10

#define N_P192V1_prime	C_P192V1+1
#define S_P192V1_prime	24
#define C_P192V1_prime	  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define N_P192V1_order	C_P192V1+2
#define	S_P192V1_order	24
#define C_P192V1_order 	  0x31, 0x28, 0xd2, 0xb4, 0xb1, 0xc9, 0x6b, 0x14,\
                          0x36, 0xf8, 0xde, 0x99, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define	N_P192V1_a	C_P192V1+3
#define S_P192V1_a	24
#define C_P192V1_a 	  0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define	N_P192V1_b	C_P192V1+4
#define S_P192V1_b	24
#define C_P192V1_b	  0xb1, 0xb9, 0x46, 0xc1, 0xec, 0xde, 0xb8, 0xfe,\
                          0x49, 0x30, 0x24, 0x72, 0xab, 0xe9, 0xa7, 0x0f,\
                          0xe7, 0x80, 0x9c, 0xe5, 0x19, 0x05, 0x21, 0x64

#define N_P192V1_Gx	C_P192V1+5
#define S_P192V1_Gx	24
#define C_P192V1_Gx 	  0x12, 0x10, 0xff, 0x82, 0xfd, 0x0a, 0xff, 0xf4,\
                          0x00, 0x88, 0xa1, 0x43, 0xeb, 0x20, 0xbf, 0x7c,\
                          0xf6, 0x90, 0x30, 0xb0, 0x0e, 0xa8, 0x8d, 0x18

#define	N_P192V1_Gy	C_P192V1+6
#define S_P192V1_Gy	24
#define C_P192V1_Gy	  0x11, 0x48, 0x79, 0x1e, 0xa1, 0x77, 0xf9, 0x73,\
                          0xd5, 0xcd, 0x24, 0x6b, 0xed, 0x11, 0x10, 0x63,\
                          0x78, 0xda, 0xc8, 0xff, 0x95, 0x2b, 0x19, 0x07

// pack all curve parameters
#define CUR_P192V1	\
                        N_P192V1_prime,    S_P192V1_prime,    C_P192V1_prime,\
                        N_P192V1_order,    S_P192V1_order,    C_P192V1_order,\
                        N_P192V1_a,        S_P192V1_a,        C_P192V1_a,\
                        N_P192V1_b,        S_P192V1_b,        C_P192V1_b,\
                        N_P192V1_Gx,       S_P192V1_Gx,       C_P192V1_Gx,\
                        N_P192V1_Gy,       S_P192V1_Gy,       C_P192V1_Gy,
 

/////////////////////////////////////////////////////////////////////////////////////////////
// curve ID (needed in ec.h/ec.c to determine fast reduction algo,
// then curve parameters incremented by 1... (prime,order,a,b,Gx,Gy)
#define C_P256V1        0x18

#define N_P256V1_prime	C_P256V1+1
#define S_P256V1_prime	32
#define C_P256V1_prime    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
                          0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff

#define N_P256V1_order	C_P256V1+2
#define S_P256V1_order	32
#define C_P256V1_order    0x51, 0x25, 0x63, 0xfc, 0xc2, 0xca, 0xb9, 0xf3,\
                          0x84, 0x9e, 0x17, 0xa7, 0xad, 0xfa, 0xe6, 0xbc,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff

#define N_P256V1_a	C_P256V1+3
#define S_P256V1_a	32
#define C_P256V1_a 	  0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
                          0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff

#define N_P256V1_b	C_P256V1+4
#define S_P256V1_b	32
#define C_P256V1_b 	  0x4b, 0x60, 0xd2, 0x27, 0x3e, 0x3c, 0xce, 0x3b,\
                          0xf6, 0xb0, 0x53, 0xcc, 0xb0, 0x06, 0x1d, 0x65,\
                          0xbc, 0x86, 0x98, 0x76, 0x55, 0xbd, 0xeb, 0xb3,\
                          0xe7, 0x93, 0x3a, 0xaa, 0xd8, 0x35, 0xc6, 0x5a

#define N_P256V1_Gx	C_P256V1+5
#define S_P256V1_Gx	32
#define C_P256V1_Gx 	  0x96, 0xc2, 0x98, 0xd8, 0x45, 0x39, 0xa1, 0xf4,\
                          0xa0, 0x33, 0xeb, 0x2d, 0x81, 0x7d, 0x03, 0x77,\
                          0xf2, 0x40, 0xa4, 0x63, 0xe5, 0xe6, 0xbc, 0xf8,\
                          0x47, 0x42, 0x2c, 0xe1, 0xf2, 0xd1, 0x17, 0x6b

#define N_P256V1_Gy	C_P256V1+6
#define S_P256V1_Gy	32
#define C_P256V1_Gy 	  0xf5, 0x51, 0xbf, 0x37, 0x68, 0x40, 0xb6, 0xcb,\
                          0xce, 0x5e, 0x31, 0x6b, 0x57, 0x33, 0xce, 0x2b,\
                          0x16, 0x9e, 0x0f, 0x7c, 0x4a, 0xeb, 0xe7, 0x8e,\
                          0x9b, 0x7f, 0x1a, 0xfe, 0xe2, 0x42, 0xe3, 0x4f
#if MP_BYTES >= 32
// pack all curve parameters
#define CUR_P256V1	\
                        N_P256V1_prime,    S_P256V1_prime,    C_P256V1_prime,\
                        N_P256V1_order,    S_P256V1_order,    C_P256V1_order,\
                        N_P256V1_a,        S_P256V1_a,        C_P256V1_a,\
                        N_P256V1_b,        S_P256V1_b,        C_P256V1_b,\
                        N_P256V1_Gx,       S_P256V1_Gx,       C_P256V1_Gx,\
                        N_P256V1_Gy,       S_P256V1_Gy,       C_P256V1_Gy,
#else
#define CUR_P256V1
#endif


/////////////////////////////////////////////////////////////////////////////////////////////
// curve ID (needed in ec.h/ec.c to determine fast reduction algo,
// then curve parameters incremented by 1... (prime,order,a,b,Gx,Gy)
#define C_SECP384R1       0x20

#define N_SECP384R1_prime  C_SECP384R1+1
#define S_SECP384R1_prime  48
#define C_SECP384R1_prime  0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\
                           0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\
                           0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define N_SECP384R1_order  C_SECP384R1+2
#define S_SECP384R1_order  48
#define C_SECP384R1_order  0x73, 0x29, 0xc5, 0xcc, 0x6a, 0x19, 0xec, 0xec,\
                           0x7a, 0xa7, 0xb0, 0x48, 0xb2, 0x0d, 0x1a, 0x58,\
                           0xdf, 0x2d, 0x37, 0xf4, 0x81, 0x4d, 0x63, 0xc7,\
                           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                           0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define N_SECP384R1_a	C_SECP384R1+3
#define S_SECP384R1_a	48
#define C_SECP384R1_a	  0xfc, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\
                          0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\
                          0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define N_SECP384R1_b	C_SECP384R1+4
#define S_SECP384R1_b	48
#define C_SECP384R1_b    0xef, 0x2a, 0xec, 0xd3, 0xed, 0xc8, 0x85, 0x2a,\
                         0x9d, 0xd1, 0x2e, 0x8a, 0x8d, 0x39, 0x56, 0xc6,\
                         0x5a, 0x87, 0x13, 0x50, 0x8f, 0x08, 0x14, 0x03,\
                         0x12, 0x41, 0x81, 0xfe, 0x6e, 0x9c, 0x1d, 0x18,\
                         0x19, 0x2d, 0xf8, 0xe3, 0x6b, 0x05, 0x8e, 0x98,\
                         0xe4, 0xe7, 0x3e, 0xe2, 0xa7, 0x2f, 0x31, 0xb3

#define N_SECP384R1_Gx	 C_SECP384R1+5
#define S_SECP384R1_Gx	48
#define C_SECP384R1_Gx     0xb7, 0x0a, 0x76, 0x72, 0x38, 0x5e, 0x54, 0x3a,\
                           0x6c, 0x29, 0x55, 0xbf, 0x5d, 0xf2, 0x02, 0x55,\
                           0x38, 0x2a, 0x54, 0x82, 0xe0, 0x41, 0xf7, 0x59,\
                           0x98, 0x9b, 0xa7, 0x8b, 0x62, 0x3b, 0x1d, 0x6e,\
                           0x74, 0xad, 0x20, 0xf3, 0x1e, 0xc7, 0xb1, 0x8e,\
                           0x37, 0x05, 0x8b, 0xbe, 0x22, 0xca, 0x87, 0xaa

#define N_SECP384R1_Gy	C_SECP384R1+6
#define S_SECP384R1_Gy	48
#define C_SECP384R1_Gy	  0x5f, 0x0e, 0xea, 0x90, 0x7c, 0x1d, 0x43, 0x7a,\
                          0x9d, 0x81, 0x7e, 0x1d, 0xce, 0xb1, 0x60, 0x0a,\
                          0xc0, 0xb8, 0xf0, 0xb5, 0x13, 0x31, 0xda, 0xe9,\
                          0x7c, 0x14, 0x9a, 0x28, 0xbd, 0x1d, 0xf4, 0xf8,\
                          0x29, 0xdc, 0x92, 0x92, 0xbf, 0x98, 0x9e, 0x5d,\
                          0x6f, 0x2c, 0x26, 0x96, 0x4a, 0xde, 0x17, 0x36
#if MP_BYTES >= 48
// pack all curve parameters
#define CUR_SECP384R1	\
                        N_SECP384R1_prime,    S_SECP384R1_prime,    C_SECP384R1_prime,\
                        N_SECP384R1_order,    S_SECP384R1_order,    C_SECP384R1_order,\
                        N_SECP384R1_a,        S_SECP384R1_a,        C_SECP384R1_a,\
                        N_SECP384R1_b,        S_SECP384R1_b,        C_SECP384R1_b,\
                        N_SECP384R1_Gx,       S_SECP384R1_Gx,       C_SECP384R1_Gx,\
                        N_SECP384R1_Gy,       S_SECP384R1_Gy,       C_SECP384R1_Gy,
#else
#define CUR_SECP384R1
#endif

/////////////////////////////////////////////////////////////////////////////////////////////
// curve ID (needed in ec.h/ec.c to determine fast reduction algo,
// then curve parameters incremented by 1... (prime,order,a,b,Gx,Gy)
#define C_SECP521R1       0x28

#define N_SECP521R1_prime  C_SECP521R1+1
#define S_SECP521R1_prime  66
#define C_SECP521R1_prime 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0x01

#define N_SECP521R1_order  C_SECP521R1+2
#define S_SECP521R1_order  66
#define C_SECP521R1_order 0x09, 0x64, 0x38, 0x91, 0x1e, 0xb7, 0x6f, 0xbb,\
                          0xae, 0x47, 0x9c, 0x89, 0xb8, 0xc9, 0xb5, 0x3b,\
                          0xd0, 0xa5, 0x09, 0xf7, 0x48, 0x01, 0xcc, 0x7f,\
                          0x6b, 0x96, 0x2f, 0xbf, 0x83, 0x87, 0x86, 0x51,\
                          0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0x01

#define N_SECP521R1_a	C_SECP521R1+3
#define S_SECP521R1_a	66
#define C_SECP521R1_a	  0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                          0xff, 0x01


#define N_SECP521R1_b	C_SECP521R1+4
#define S_SECP521R1_b	66
#define C_SECP521R1_b    0x00, 0x3f, 0x50, 0x6b, 0xd4, 0x1f, 0x45, 0xef,\
                         0xf1, 0x34, 0x2c, 0x3d, 0x88, 0xdf, 0x73, 0x35,\
                         0x07, 0xbf, 0xb1, 0x3b, 0xbd, 0xc0, 0x52, 0x16,\
                         0x7b, 0x93, 0x7e, 0xec, 0x51, 0x39, 0x19, 0x56,\
                         0xe1, 0x09, 0xf1, 0x8e, 0x91, 0x89, 0xb4, 0xb8,\
                         0xf3, 0x15, 0xb3, 0x99, 0x5b, 0x72, 0xda, 0xa2,\
                         0xee, 0x40, 0x85, 0xb6, 0xa0, 0x21, 0x9a, 0x92,\
                         0x1f, 0x9a, 0x1c, 0x8e, 0x61, 0xb9, 0x3e, 0x95,\
                         0x51, 0x00

#define N_SECP521R1_Gx	C_SECP521R1+5
#define S_SECP521R1_Gx	66
#define C_SECP521R1_Gx    0x66, 0xbd, 0xe5, 0xc2, 0x31, 0x7e, 0x7e, 0xf9,\
                          0x9b, 0x42, 0x6a, 0x85, 0xc1, 0xb3, 0x48, 0x33,\
                          0xde, 0xa8, 0xff, 0xa2, 0x27, 0xc1, 0x1d, 0xfe,\
                          0x28, 0x59, 0xe7, 0xef, 0x77, 0x5e, 0x4b, 0xa1,\
                          0xba, 0x3d, 0x4d, 0x6b, 0x60, 0xaf, 0x28, 0xf8,\
                          0x21, 0xb5, 0x3f, 0x05, 0x39, 0x81, 0x64, 0x9c,\
                          0x42, 0xb4, 0x95, 0x23, 0x66, 0xcb, 0x3e, 0x9e,\
                          0xcd, 0xe9, 0x04, 0x04, 0xb7, 0x06, 0x8e, 0x85,\
                          0xc6, 0x00

#define N_SECP521R1_Gy	C_SECP521R1+6
#define S_SECP521R1_Gy	66
#define C_SECP521R1_Gy	  0x50, 0x66, 0xd1, 0x9f, 0x76, 0x94, 0xbe, 0x88,\
                          0x40, 0xc2, 0x72, 0xa2, 0x86, 0x70, 0x3c, 0x35,\
                          0x61, 0x07, 0xad, 0x3f, 0x01, 0xb9, 0x50, 0xc5,\
                          0x40, 0x26, 0xf4, 0x5e, 0x99, 0x72, 0xee, 0x97,\
                          0x2c, 0x66, 0x3e, 0x27, 0x17, 0xbd, 0xaf, 0x17,\
                          0x68, 0x44, 0x9b, 0x57, 0x49, 0x44, 0xf5, 0x98,\
                          0xd9, 0x1b, 0x7d, 0x2c, 0xb4, 0x5f, 0x8a, 0x5c,\
                          0x04, 0xc0, 0x3b, 0x9a, 0x78, 0x6a, 0x29, 0x39,\
                          0x18, 0x01
/*
// Xs and Ys from NIST example calculations
#define N_SECP521R1_XS	46
#define S_SECP521R1_XS	66
#define C_SECP521R1_XS  0xb4, 0xc1, 0xd5, 0xda, 0xf6, 0x0e, 0x93, 0x89,\
                        0xb0, 0x04, 0xaf, 0x39, 0x7d, 0x0a, 0x2d, 0x8e,\
                        0xfd, 0x8b, 0x2b, 0x8b, 0x6a, 0xc1, 0x8d, 0xcf,\
                        0x7b, 0x84, 0xfc, 0x57, 0xa1, 0x4a, 0xb8, 0x0b,\
                        0x0b, 0x74, 0x50, 0xaf, 0x73, 0x28, 0xf6, 0x4b,\
                        0x7b, 0x22, 0xd0, 0xd3, 0x98, 0xd0, 0x1f, 0x60,\
                        0x8f, 0x45, 0x43, 0x74, 0x93, 0x1f, 0x03, 0x0f,\
                        0xad, 0x03, 0xed, 0x08, 0x6c, 0xf6, 0x93, 0xc6,\
                        0xd5, 0x01

#define N_SECP521R1_YS	47
#define S_SECP521R1_YS	66
#define C_SECP521R1_YS  0x23, 0x18, 0xc0, 0x1a, 0xe6, 0x7a, 0xea, 0x66,\
                        0xfa, 0xe3, 0x4e, 0x76, 0x49, 0x6e, 0x55, 0x5b,\
                        0xee, 0xfc, 0x89, 0xdb, 0x07, 0x1e, 0xa1, 0xba,\
                        0x9e, 0xc8, 0x3a, 0xa6, 0xc1, 0xb7, 0xb2, 0x37,\
                        0xd0, 0x8e, 0x81, 0x2b, 0x01, 0x54, 0x4c, 0x66,\
                        0xc8, 0xf5, 0x4a, 0x22, 0x9b, 0x54, 0x33, 0xac,\
                        0x1e, 0x15, 0x74, 0xb0, 0x36, 0xff, 0x65, 0x88,\
                        0x24, 0x39, 0x3a, 0xc6, 0x63, 0x09, 0x77, 0xb7,\
                        0x44, 0x01

#define N_SECP521R1_D	48
#define S_SECP521R1_D	66
#define C_SECP521R1_D  	0xb1, 0xdc, 0x9f, 0xc8, 0xcf, 0xed, 0xf0, 0xfc,\
                        0x6d, 0xde, 0x00, 0x66, 0x2d, 0x1b, 0xd4, 0x94,\
                        0x72, 0x5c, 0x69, 0x0a, 0x94, 0xda, 0xd6, 0xf0,\
                        0x4d, 0x96, 0x53, 0x26, 0xb6, 0x78, 0x6c, 0x93,\
                        0xa9, 0xbf, 0x19, 0x94, 0x69, 0x66, 0xa1, 0xa5,\
                        0x6f, 0x86, 0x2a, 0x1a, 0x11, 0x54, 0x55, 0x73,\
                        0x09, 0x71, 0x95, 0x74, 0xc6, 0xf8, 0xe8, 0xa7,\
                        0x36, 0xf1, 0x29, 0x96, 0x5c, 0x78, 0x81, 0x7f,\
                        0xeb, 0x01
*/
#if MP_BYTES >= 66
// pack all curve parameters
#define CUR_SECP521R1	\
                        N_SECP521R1_prime,    S_SECP521R1_prime,    C_SECP521R1_prime,\
                        N_SECP521R1_order,    S_SECP521R1_order,    C_SECP521R1_order,\
                        N_SECP521R1_a,        S_SECP521R1_a,        C_SECP521R1_a,\
                        N_SECP521R1_b,        S_SECP521R1_b,        C_SECP521R1_b,\
                        N_SECP521R1_Gx,       S_SECP521R1_Gx,       C_SECP521R1_Gx,\
                        N_SECP521R1_Gy,       S_SECP521R1_Gy,       C_SECP521R1_Gy,
#else
#define CUR_SECP521R1
#endif

/////////////////////////////////////////////////////////////////////////////////////////////
// curve ID (needed in ec.h/ec.c to determine fast reduction algo,
// then curve parameters incremented by 1... (prime,order,a,b,Gx,Gy)
#define C_SECP256K1       0x30


#define N_SECP256K1_prime	C_SECP256K1+1
#define S_SECP256K1_prime	32
#define C_SECP256K1_prime       0x2f, 0xfc, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff,\
                                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

#define N_SECP256K1_order	C_SECP256K1+2
#define S_SECP256K1_order	32
#define C_SECP256K1_order       0x41, 0x41, 0x36, 0xd0, 0x8c, 0x5e, 0xd2, 0xbf,\
                                0x3b, 0xa0, 0x48, 0xaf, 0xe6, 0xdc, 0xae, 0xba,\
                                0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
                                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff


#define N_SECP256K1_a		C_SECP256K1+3
#define S_SECP256K1_a		32
#define C_SECP256K1_a 	  	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

#define N_SECP256K1_b		C_SECP256K1+4
#define S_SECP256K1_b		32
#define C_SECP256K1_b 	  	7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

#define N_SECP256K1_Gx		C_SECP256K1+5
#define S_SECP256K1_Gx		32
#define C_SECP256K1_Gx 	 	0x98, 0x17, 0xf8, 0x16, 0x5b, 0x81, 0xf2, 0x59,\
                                0xd9, 0x28, 0xce, 0x2d, 0xdb, 0xfc, 0x9b, 0x02,\
                                0x07, 0x0b, 0x87, 0xce, 0x95, 0x62, 0xa0, 0x55,\
                                0xac, 0xbb, 0xdc, 0xf9, 0x7e, 0x66, 0xbe, 0x79

#define N_SECP256K1_Gy		C_SECP256K1+6
#define S_SECP256K1_Gy		32
#define C_SECP256K1_Gy		0xb8, 0xd4, 0x10, 0xfb, 0x8f, 0xd0, 0x47, 0x9c,\
                                0x19, 0x54, 0x85, 0xa6, 0x48, 0xb4, 0x17, 0xfd,\
                                0xa8, 0x08, 0x11, 0x0e, 0xfc, 0xfb, 0xa4, 0x5d,\
                                0x65, 0xc4, 0xa3, 0x26, 0x77, 0xda, 0x3a, 0x48

#if defined(NIST_ONLY) || MP_BYTES <32
#define CUR_SECP256K1
#else
#define CUR_SECP256K1   \
                        N_SECP256K1_prime, S_SECP256K1_prime, C_SECP256K1_prime,\
                        N_SECP256K1_order, S_SECP256K1_order, C_SECP256K1_order,\
                        N_SECP256K1_a,     S_SECP256K1_a,     C_SECP256K1_a,\
                        N_SECP256K1_b,     S_SECP256K1_b,     C_SECP256K1_b,\
                        N_SECP256K1_Gx,    S_SECP256K1_Gx,    C_SECP256K1_Gx,\
                        N_SECP256K1_Gy,    S_SECP256K1_Gy,    C_SECP256K1_Gy,
#endif

#if 1
#define DIGEST_PREFIXES \
                        N_PSHA1_prefix,    S_PSHA1_prefix,    C_PSHA1_prefix,
#else
#define DIGEST_PREFIXES \
                        N_PSHA1_prefix,    S_PSHA1_prefix,    C_PSHA1_prefix,\
                        N_PSHA224_prefix,  S_PSHA224_prefix,  C_PSHA224_prefix,\
                        N_PSHA256_prefix,  S_PSHA256_prefix,  C_PSHA256_prefix,\
                        N_PSHA384_prefix,  S_PSHA384_prefix,  C_PSHA384_prefix,\
                        N_PSHA512_prefix,  S_PSHA384_prefix,  C_PSHA512_prefix,
#endif

#define C_CONSTANTS \
  CUR_SECP521R1\
  CUR_SECP384R1\
  CUR_P256V1\
  CUR_P192V1\
  CUR_SECP256K1\
  DIGEST_PREFIXES\
  N_CARD_ID,	     S_CARD_ID,	        C_CARD_ID,\
  N_CARD_CAP_ID,     S_CARD_CAP_ID,     C_CARD_CAP_ID,\
  N_GCD_PRIMES,      S_GCD_PRIMES,      C_GCD_PRIMES,\
  N_FS_INIT_DATA,    S_FS_INIT_DATA,	C_FS_INIT_DATA,\
/* *INDENT-ON* */


#ifndef __ASSEMBLER__
uint8_t get_constant (void *here, uint8_t id);
#endif
#endif
